package com.tanhua.controller;


import com.tanhua.server.SettingsService;
import com.tanhua.vo.PageResult;
import com.tanhua.vo.SettingsVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/*
* 自己封装一个类以vo结尾，将三个实体类的内容封装在这一个类中进行响应给前端
* */
@RestController
@RequestMapping("/users")
public class SettingsController {
    @Autowired
    private SettingsService settingsService;
    /*
    查询全部的设置
    * */
    @GetMapping("/settings")
    public ResponseEntity settings(){
        SettingsVo vo =settingsService.settings();
        return ResponseEntity.ok(vo);
    }
    /*
    设置陌生人问题
    * */
    @PostMapping("/questions")
    public ResponseEntity questions(@RequestBody Map map){
        String content = (String)map.get("content");
        settingsService.saveQuestion(content);
        return ResponseEntity.ok(null);
    }
    /*
    * 设置是否通知
    * */
    @PostMapping("notifications/setting")
    public ResponseEntity notifications(@RequestBody Map map ){
        settingsService.saveNotifications(map);
        return ResponseEntity.ok(null);
    }
    /*
    * 查询黑名单列表
    * */
    @GetMapping("/blacklist")
    public ResponseEntity blacklist(@RequestParam(defaultValue = "1")int page,
                                    @RequestParam(defaultValue = "2")int size){
        PageResult pr = settingsService.blacklist(page,size);
        return ResponseEntity.ok(pr);
    }
    /*
    * 将好友从列表中删除
    * */
    @DeleteMapping("/blacklist/{uid}")
    public ResponseEntity blacklistUid(@PathVariable("uid") Long blackUserId){
        settingsService.blacklistUid(blackUserId);
        return ResponseEntity.ok(null);
    }
}
